﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using Eg.Core;

namespace Queries
{
    class Program
    {
        static void Main(string[] args)
        {
        }
        static void RunQueries(ISession session)
        {
 
        }

        static void Show(string heading, IEnumerable<Movie> movies)
        {
            Console.WriteLine(heading);
            foreach (var m in movies)
            {
                showMovie(m);
                Console.WriteLine();
            }
        }
        static void Show(string heading, Book book)
        {
            Console.WriteLine(heading);
            showBook(book);
            Console.WriteLine();
        }
        static void Show(string heading, IEnumerable<Product> products)
        {
            Console.WriteLine(heading);
            foreach (var p in products)
            {
                if (p is Movie)
                {
                    showMovie(p);
                }
                else if (p is Book)
                {
                    showBook(p);
                }
                else
                {
                    showProduct(p);
                }
            }
            Console.WriteLine();
        }
        static void Show(string heading, decimal moneyValue)
        {
            Console.WriteLine(heading);
            Console.WriteLine("{0:c}", moneyValue);
            Console.WriteLine();
        }
        static void Show(string heading, IEnumerable<NameAndPrice> results)
        {
            Console.WriteLine(heading);
            foreach (var item in results)
            {
                ShowNameAndPrice(item);
            }
            Console.WriteLine();
        }
        static void ShowNameAndPrice(NameAndPrice item)
        {
            Console.WriteLine("{0:c} {1}", item.Price, item.Name);
        }
        static void ShowProduct(Product p)
        {
            Console.WriteLine("{0:c} {1}",p.UnitPrice, p.Name);
        }
        static void ShowBook(Book book)
        {
            Console.WriteLine("{0:c} {1} (ISBN {2})", book.UnitPrice, book.Name, book.ISBN);
        }
        static void ShowMovie(Movie movie)
        {
            var star = movie.Actors
                .Select(actorRole => actorRole.Actor)
                .FirstOrDefault();

            Console.WriteLine("{0:c} {1} starring {2}", movie.UnitPrice, movie.Name, star ?? "nobody");
        }
    }
}
